#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QBoxLayout>

MainWindow* MainWindow::sInst = nullptr;
QMutex MainWindow::sInsMutex;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::SetTopWidget(QWidget *w)
{
    if(!w)return;
    QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom);
    layout->setMargin(0);
    layout->setSpacing(0);
    w->setParent(ui->topwidget);
    layout->addWidget(w);
    ui->topwidget->setLayout(layout);
}

void MainWindow::SetButtomWidget(QWidget *w)
{
    if(!w)return;
    QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom);
    layout->setMargin(0);
    layout->setSpacing(0);
    w->setParent(ui->buttomwidget);
    layout->addWidget(w);
    ui->buttomwidget->setLayout(layout);
}

void MainWindow::SetLeftWidget(QWidget *w)
{
    if(!w)return;
    QBoxLayout* layout = new QBoxLayout(QBoxLayout::LeftToRight);
    layout->setMargin(0);
    layout->setSpacing(0);
    w->setParent(ui->leftwidget);
    layout->addWidget(w);
    ui->leftwidget->setLayout(layout);
}

void MainWindow::SetRightWidget(QWidget *w)
{
    if(!w)return;
    QBoxLayout* layout = new QBoxLayout(QBoxLayout::LeftToRight);
    layout->setMargin(0);
    layout->setSpacing(0);
    w->setParent(ui->rightwidget);
    layout->addWidget(w);
    ui->rightwidget->setLayout(layout);
}

void MainWindow::SetCenterWidget(QWidget *w)
{
    if(!w)return;
    QBoxLayout* layout = new QBoxLayout(QBoxLayout::LeftToRight);
    layout->setMargin(0);
    layout->setSpacing(0);
    w->setParent(ui->centerwidget);
    layout->addWidget(w);
    ui->centerwidget->setLayout(layout);
}
